package xin.sunzy.spring.model;

import lombok.Data;

/**
 * @description: 请求响应实体
 * @email: <a href="sunzhenyu@terminus.io">孙振宇</a>
 * @author: ginkgo
 * @date: 2018/4/3
 */
@Data
public class PageBean {

    public static final Integer SUCCESS_CODE = 200;

    public static final Integer ERROR_CODE = 500;

    private Integer code;

    private String message;

    private Object result;

    public PageBean(Integer code) {
        this.code = code;
    }

    public PageBean(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public PageBean(Integer code, Object result) {
        this.code = code;
        this.result = result;
    }

    public PageBean(Integer code, String message, Object result) {
        this.code = code;
        this.message = message;
        this.result = result;
    }

    public static PageBean ok() {
        return ok(null);
    }

    public static PageBean ok(Object result) {
        return ok(null, result);
    }

    public static PageBean ok(String message) {
        return ok(message, null);
    }

    public static PageBean ok(String message, Object result) {
        return new PageBean(SUCCESS_CODE, message, result);
    }

    public static PageBean fail(String message) {
        return new PageBean(ERROR_CODE, message);
    }
}
